//
//  YAYIPageControl.m
//  yayi
//
//  Created by Veer on 16/3/31.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYIPageControl.h"

@implementation YAYIPageControl
{
    
    UIImage* activeImage;
    
    UIImage* inactiveImage;
    
}

-(id) initWithFrame:(CGRect)frame

{
    
    self = [super initWithFrame:frame];
    
    
    activeImage = [UIImage imageNamed:@"home_pageControl_highlight"];
    
    inactiveImage = [UIImage imageNamed:@"home_pageControl_normal"];
    
    
    return self;
    
}


-(void) updateDots

{
    for (int i=0; i<[self.subviews count]; i++) {
        
        UIView* dot = [self.subviews objectAtIndex:i];
        
        CGSize size;
        
        size.height = 8;     //自定义圆点的大小
        
        size.width = 8;      //自定义圆点的大小
        [dot setFrame:CGRectMake(dot.frame.origin.x, dot.frame.origin.y, size.width, size.width)];
//        if (i == self.currentPage)dot.image = activeImage;
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"home_pageControl_highlight"];
        imageView.frame = dot.bounds;
        
        UIImageView *imageView2 = [[UIImageView alloc] init];
        imageView2.image = [UIImage imageNamed:@"home_pageControl_normal"];
        imageView2.frame = dot.bounds;
        
        for (UIImageView *imageView in dot.subviews) {
            [imageView removeFromSuperview];
        }
        if (i == self.currentPage){
//            [dot addSubview:imageView];
        }else {
            [dot addSubview:imageView2];
        }
    }
    
}

-(void) setCurrentPage:(NSInteger)page

{
    
    [super setCurrentPage:page];
    
    [self updateDots];
    
}


@end
